

using System;
using System.Numerics;

namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_Absolute_RT : RT_Node
    {
        public RT_SingleValuePort Value_RT;

        public RT_SingleValuePort Absolute_RT;

        public Node_Absolute_RT(Node_Absolute sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            Value_RT = new RT_SingleValuePort(EPortIOType.Input, sourceData.Value, this);

            Absolute_RT = new RT_SingleValuePort(EPortIOType.Output, sourceData.Absolute, this);
            Absolute_RT.OnGetValue = GetAbsolute;
        }

        public AValue GetAbsolute(DAG_Executor executor)
        {
            Absolute_RT.SourceValue.Reset();
            var valueType = Absolute_RT.SourceValue.ValueType;
            if (valueType == AValue.EValueType.Integer)
            {
                int intV = Value_RT.GetValue(executor).ToInteger().Item2;
                Absolute_RT.SourceValue.SetInteger(Math.Abs(intV));
            }
            else if (valueType == AValue.EValueType.Scalar)
            {
                float floatV = Value_RT.GetValue(executor).ToScalar().Item2;
                Absolute_RT.SourceValue.SetScalar(Math.Abs(floatV));
            }
            else if (valueType == AValue.EValueType.Vector2)
            {
                Vector2 vec2 = Value_RT.GetValue(executor).ToVector2().Item2;
                Absolute_RT.SourceValue.SetVector2(vec2);
            }
            else if (valueType == AValue.EValueType.Vector3)
            {
                Vector3 vec3 = Value_RT.GetValue(executor).ToVector3().Item2;
                Absolute_RT.SourceValue.SetVector3(vec3);
            }
            return Absolute_RT.SourceValue;
        }


    }
}